//
//  ReadScrollBomView.swift
//  WalkNovel
//
//  Created by Kevin on 2023/8/3.
//

import UIKit

class ReadScrollTopView: UIView {
    
    lazy var chapterLabel: UILabel = {
        let label = UILabel()
        label.font = .wn_font(name: .bold, size: 16)
        return label
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(chapterLabel)
        chapterLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(StatusBarHeight+2)
        }
    }
    
    func darkModeConfig() {
        backgroundColor = isDark() ? .init(named: "black_121212") : .wn_colorWithHexString("\(getReadConfigItem("bgColor"))")
        chapterLabel.textColor = isDark() ? .init(named: "gray_777777") : .black
        layoutIfNeeded()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

class ReadScrollBomView: UIView {
    
    lazy var chapterLabel: UILabel = {
        let label = UILabel()
        label.font = .wn_font(name: .bold, size: 12)
        return label
    }()
    
    lazy var pageLabel: UILabel = {
        let label = UILabel()
        label.font = .wn_font(name: .bold, size: 12)
        label.textAlignment = .right
        return label
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(chapterLabel)
        addSubview(pageLabel)
        chapterLabel.snp.makeConstraints { make in
            make.left.equalTo(12)
            make.top.equalTo(10)
        }
        pageLabel.snp.makeConstraints { make in
            make.top.equalTo(10)
            make.right.equalTo(-12)
        }
    }
    
    func darkModeConfig() {
        backgroundColor = isDark() ? .init(named: "black_121212") : .wn_colorWithHexString("\(getReadConfigItem("bgColor"))")
        chapterLabel.textColor = isDark() ? .init(named: "gray_777777") : .black
        pageLabel.textColor = isDark() ? .init(named: "gray_777777") : .black
        let fontStr = wn_toString(getReadConfigItem("font"))
        var fontName = UIFont.ESFontName.regular
        if fontStr == "regular" {
            fontName = .regular
        }else if fontStr == "floane" {
            fontName = .floane
        }else if fontStr == "national" {
            fontName = .national
        }else if fontStr == "medium" {
            fontName = .medium
        }
        chapterLabel.font = .wn_font(name: fontName, size: 12)
        pageLabel.font = .wn_font(name: fontName, size: 12)
        layoutIfNeeded()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

